import time

from django.shortcuts import get_object_or_404, redirect
from django.contrib.auth.decorators import login_required
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect

from brispon.util.decorators import render_to, ajax_request
from brispon.util import BaseSearchForm, paginate, inc_paginate
from brispon.models import Recruit

class RecruitForm(BaseSearchForm):
    class Meta:
        base_qs = Recruit.objects
        search_fields = ('name', 'description') 
        default_fields = {}

@render_to('d/recruit/list.html')
def list(request):
    if request.is_mobile:
        return redirect('brispon.views.recruit.mlist')
    coupon_form = RecruitForm(request.GET or None)
    return paginate(request.GET, search_form=coupon_form, unit_page=15)

@render_to('m/recruit/list.html')
def mlist(request):
    if not request.is_mobile:
        return redirect('brispon.views.recruit.list')
    coupon_form = RecruitForm(request.GET or None)
    return paginate(request.GET, search_form=coupon_form, unit_page=12)

@render_to('m/recruit/detail.html')
def mdetail(request, recruit_id):
    recruit = get_object_or_404(Recruit, pk=recruit_id)
    return {'recruit':recruit}